import img2pdf

import os
 

path="imgs"
dir_list = os.listdir(path)
dir_list.sort(key=lambda x:int(x.split('.')[0]))
images=[]
for cur_file in dir_list:
 print(os.path.join(path,cur_file))
 images.append(os.path.join(path,cur_file))

##images = ["imgs/1.png", "imgs/2.png", "imgs/3.png"]
output = "file1.pdf"
 
# 创建一个PDF文件 并以二进制方式写入
with open(output, "wb") as f:
 # convert函数 用来转PDF
 write_content = img2pdf.convert(images)
 f.write(write_content) # 写入文件
print("转换成功！") # 提示语